455284 - Focus or toggle location entry
authorFederico Mena Quintero <federico@novell.com>
Tue, 2 Oct 2007 15:50:27 +0000 (15:50 +0000)
committerFederico Mena Quintero <federico@src.gnome.org>
Tue, 2 Oct 2007 15:50:27 +0000 (15:50 +0000)
2007-10-02  Federico Mena Quintero  <federico@novell.com>

Fix http://bugzilla.gnome.org/show_bug.cgi?id=455284 - In the file
chooser, Ctrl-L should switch to the location entry.  If we are
already on the location entry, turn it off.  Based on a patch by
Jaap A. Haitsma <jaap@haitsma.org> and an idea by Wouter
Bolsterlee.

* gtk/gtkfilechooserdefault.c (location_button_toggled_cb): Call
location_mode_set() directly instead of using toggle_location_mode().
(toggle_location_mode): Removed.
(location_toggle_popup_handler): If the file entry is not visible,
show it.  If it is visible, turn it off only if it is focused.
Otherwise, switch to the entry.

Signed-off-by: Federico Mena Quintero <federico@gnu.org>
svn path=/trunk/; revision=18874

ChangeLog
gtk/gtkfilechooserdefault.c

index 249178044486b9c5fe2a283afff5b505fdaba2a4..07df869d1ace05c46424ecb3c2db689e1fda3d24 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2007-10-02  Federico Mena Quintero  <federico@novell.com>
+
+       Fix http://bugzilla.gnome.org/show_bug.cgi?id=455284 - In the file
+       chooser, Ctrl-L should switch to the location entry.  If we are
+       already on the location entry, turn it off.  Based on a patch by
+       Jaap A. Haitsma <jaap@haitsma.org> and an idea by Wouter
+       Bolsterlee.
+
+       * gtk/gtkfilechooserdefault.c (location_button_toggled_cb): Call
+       location_mode_set() directly instead of using toggle_location_mode().
+       (toggle_location_mode): Removed.
+       (location_toggle_popup_handler): If the file entry is not visible,
+       show it.  If it is visible, turn it off only if it is focused.
+       Otherwise, switch to the entry.
+
 2007-10-01  Kristian Rietveld  <kris@imendio.com>
 
        * gtk/gtktreeviewcolumn.c (gtk_tree_view_column_update_button):
index 484f701d155aad14d59da12ab1fb2090db3410ff..819320d84d54e748e016971579bb404d1ada435e 100644 (file)
@@ -5141,23 +5141,27 @@ location_mode_set (GtkFileChooserDefault *impl,
   impl->location_mode = new_mode;
 }
 
-static void
-toggle_location_mode (GtkFileChooserDefault *impl,
-                      gboolean               set_button)
-{
-  LocationMode new_mode;
-
-  /* toggle value */
-  new_mode = (impl->location_mode == LOCATION_MODE_PATH_BAR) ?
-    LOCATION_MODE_FILENAME_ENTRY : LOCATION_MODE_PATH_BAR;
-
-  location_mode_set (impl, new_mode, set_button);
-}
-
 static void
 location_toggle_popup_handler (GtkFileChooserDefault *impl)
 {
-  toggle_location_mode (impl, TRUE);
+  /* If the file entry is not visible, show it.
+   * If it is visible, turn it off only if it is focused.  Otherwise, switch to the entry.
+   */
+  if (impl->location_mode == LOCATION_MODE_PATH_BAR)
+    {
+      location_mode_set (impl, LOCATION_MODE_FILENAME_ENTRY, TRUE);
+    }
+  else if (impl->location_mode == LOCATION_MODE_FILENAME_ENTRY)
+    {
+      if (GTK_WIDGET_HAS_FOCUS (impl->location_entry))
+        {
+          location_mode_set (impl, LOCATION_MODE_PATH_BAR, TRUE);
+        }
+      else
+        {
+          gtk_widget_grab_focus (impl->location_entry);
+        }
+    }
 }
 
 /* Callback used when one of the location mode buttons is toggled */
@@ -5166,15 +5170,22 @@ location_button_toggled_cb (GtkToggleButton *toggle,
                            GtkFileChooserDefault *impl)
 {
   gboolean is_active;
+  LocationMode new_mode;
 
   is_active = gtk_toggle_button_get_active (toggle);
 
   if (is_active)
-    g_assert (impl->location_mode == LOCATION_MODE_PATH_BAR);
+    {
+      g_assert (impl->location_mode == LOCATION_MODE_PATH_BAR);
+      new_mode = LOCATION_MODE_FILENAME_ENTRY;
+    }
   else
-    g_assert (impl->location_mode == LOCATION_MODE_FILENAME_ENTRY);
+    {
+      g_assert (impl->location_mode == LOCATION_MODE_FILENAME_ENTRY);
+      new_mode = LOCATION_MODE_PATH_BAR;
+    }
 
-  toggle_location_mode (impl, FALSE);
+  location_mode_set (impl, new_mode, FALSE);
 }
 
 /* Creates a toggle button for the location entry. */